

/**
 * @file BiasDataReader.hpp
 * Class to read Bias data.
 */

#ifndef BIAS_DATA_READER_HPP
#define BIAS_DATA_READER_HPP


#include <string>
#include <map>

#include "Exception.hpp"
#include "FFTextStream.hpp"
#include "StringUtils.hpp"
#include "SatID.hpp"
#include "TypeID.hpp"
#include "Epoch.hpp"


namespace gpstk
{

      /** @addtogroup formattedfile */
      //@{

    class BiasDataReader : public FFTextStream
    {
    public:
         /// Default constructor
        BiasDataReader() {};

         /** Common constructor. It will always open file for read and will
          *  load Bias data in one pass.
          *
          * @param fn   Bias data file to read
          *
          */
        BiasDataReader(const char* fn)
            : FFTextStream(fn, std::ios::in)
        {
            FFTextStream(fn, std::ios::in);
            if( !FFTextStream::is_open() )
            {
                std::cerr << "The file " << fn << "doesn't exist!" << std::endl;
                exit(-1);
            }

            loadData();
        }


         /** Common constructor. It will always open file for read and will
          *  load Bias data in one pass.
          *
          * @param fn   Bias data file to read
          *
          */
        BiasDataReader(const std::string& fn)
        {
            FFTextStream(fn, std::ios::in);
            if( !FFTextStream::is_open() )
            {
                std::cerr << "The file " << fn << "doesn't exist!" << std::endl;
                exit(-1);
            }

            loadData();
        }

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverloaded-virtual"
        /// Method to open AND load Bias data file.
        virtual void open(const char* fn);


        /// Method to open AND load Bias data file. It doesn't
        /// clear data previously loaded.
        virtual void open(const std::string& fn);
#pragma clang diagnostic pop


        double getSatBias( const SatID& sat,
                           const std::string& type1,
                           const std::string& type2,
                           const CommonTime& time );


        /// Destructor
        virtual ~BiasDataReader() {};


    private:

        std::string mode;

        struct BiasData
        {
            BiasData()
                : start(CommonTime::BEGINNING_OF_TIME),
                  end(CommonTime::END_OF_TIME),
                  value(0.0), std(0.0)
            {};

            CommonTime start;
            CommonTime end;

            double value;
            double std;
        };


        // key  - PRN + OBS1 + OBS2
        // data - TIME1 + TIME2 + VALUE + STD
        std::multimap<std::string, BiasData> satBiasData;


        /// Method to store Bias data in this class' data map
        virtual void loadData()
            noexcept(false);

    };  // End of class 'BiasDataReader'

    //@}

}  // End of namespace gpstk

#endif  // BIAS_DATA_READER_HPP
